﻿Public Class frmSA_Viewer

    Private Sub btnAddNew_Click(sender As Object, e As EventArgs) Handles btnAddNew.Click
        frmSA_AED.btnEdite.Text = "រក្សាទុក"
        frmSA_AED.ShowDialog()
    End Sub

    Private Sub btnEdite_Click(sender As Object, e As EventArgs) Handles btnEdite.Click

        If Me.dgv.SelectedRows.Count = 0 Then
            Exit Sub
        End If
        Dim row = dgv.SelectedRows(0)
        Dim frm = New frmSA_AED
        frm.txtID.Text = row.Cells("SA_id").Value
        frm.txtSACode.Text = row.Cells("SA_code").Value
        frm.txtSAName.Text = row.Cells("SA_name").Value
        frm.cboSex.Text = row.Cells("sex").Value
        frm.txtTel.Text = row.Cells("phone").Value
        frm.txtEmail.Text = row.Cells("Email").Value
        frm.txtAdr.Text = row.Cells("isaddress").Value
        frm.cboProvince.Text = row.Cells("pro_Name").Value
        frm.btnEdite.Text = "កែប្រែ"
        If (frm.ShowDialog = Windows.Forms.DialogResult.OK) Then
            LoadData()
        End If

    End Sub

    Public Sub LoadData()

        Cmd.Parameters("@s") = txtSearch.Text
        Me.dgv.DataSource = Cmd.ExecuteDataTable("SELECT SA_id ,SA_code,SA.SA_name,phone ,email ,isaddress ,sex, P.pro_Name FROM tblSA SA INNER JOIN tblsex S on S.sex_id = SA.sex_id INNER JOIN tblProvice P on P.Pro_id = SA.provice_id  WHERE UPPER(SA_name) LIKE UPPER('%'+@s+'%') AND SA.Active = 1")

    End Sub

    Private Sub frmSA_Viewer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        UI.FormatDataGrid(dgv)

        LoadData()

    End Sub
End Class